package cn.usian.service.impl;

import cn.usian.feign.ProjectFeign;
import cn.usian.mapper.DailyVoMapper;
import cn.usian.pojo.Daily;
import cn.usian.service.DailyVoService;
import cn.usian.vo.DailyVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.stream.Collectors;

@Service
public class DailyVoServiceImpl extends ServiceImpl<DailyVoMapper, DailyVo> implements DailyVoService {
    @Autowired
    ProjectFeign projectFeign;

    @Override
    public Page<DailyVo> findPage(Integer pageNum, Integer pageSize,Daily daily) {
        Page<DailyVo> page = new Page<>(pageNum, pageSize);
        page = this.baseMapper.findPage(page,daily);
        page.getRecords().stream().map( dailyVo -> {
            dailyVo.setPname(projectFeign.findProjectByName(dailyVo.getPid()).getName());
            return dailyVo;
        }).collect(Collectors.toList());
        return page;
    }

    @Override
    public void add(Daily daily) {
        this.baseMapper.add(daily);
    }

    @Override
    public void updateDaily(Daily daily) {
        this.baseMapper.updateDaily(daily);
    }

    @Override
    public Daily findDaylyById(Integer id) {
        return this.baseMapper.findDaylyById(id);
    }

}
